/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package autowus.gui.appointment;

import autowus.gui.module.MainFrame;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import polaczenie.polacz;

/**
 *
 * @author Quark
 */
public class AppointmentFrame extends javax.swing.JFrame {

    private javax.swing.JButton addBtn;
    private javax.swing.JPanel calendarPanel;
    private javax.swing.JPanel contentPanel;
    private javax.swing.JLabel copyrightLabel;
    private javax.swing.JTextField idTextField;
    private javax.swing.JLabel logoLabel;
    private javax.swing.JTextField peselNoTexField;
    private javax.swing.JSpinner timeSpinner;
    private javax.swing.JPanel wrappingPanel;
    
    private Date time;
    private String formattedTime;
    
    ExampleDateChangeListener exDCL = new ExampleDateChangeListener();
    
    /**
     * Creates new form AppointmentFrame
     */
    public AppointmentFrame() {
        initComponents();
        initCustom();
        
        addBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evnt) {
                polacz p = new polacz();
                p.laczZBD();
                p.dodajWizyte(p.id_wizyty_max(), exDCL.calendar.format("yyyy-MM-dd"), formattedTime, idTextField.getText(), Long.parseLong(peselNoTexField.getText()));
                p.dodajSprawdzenie(peselNoTexField.getText());
                System.out.println("addBtn clicked.");
            }
        });
        
        timeSpinner.addChangeListener(new ChangeListener () {
            @Override
            public void stateChanged(ChangeEvent e) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm");
                time = (Date)(((JSpinner)e.getSource()).getValue());
                formattedTime = simpleDateFormat.format(time);
                System.out.println(formattedTime);
            }
        });
    }

    private void initCustom() {
        Image icon = null;
        try {
            icon = ImageIO.read(getClass().getResource("/autowus/gui/graphics/appointment/autoWUŚ_check_logo.png"));
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.setIconImage(icon);
        
        this.setTitle("Dodaj wizytę");
        this.setLayout(null);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        
        wrappingPanel = new javax.swing.JPanel();
        contentPanel = new javax.swing.JPanel();
        logoLabel = new javax.swing.JLabel();
        peselNoTexField = new javax.swing.JTextField();
        idTextField = new javax.swing.JTextField();
        calendarPanel = new javax.swing.JPanel();
        timeSpinner = new javax.swing.JSpinner();
        addBtn = new javax.swing.JButton();
        copyrightLabel = new javax.swing.JLabel();
        
        wrappingPanel.setBackground(new java.awt.Color(2, 148, 75));
        wrappingPanel.setLayout(null);
        wrappingPanel.setMaximumSize(new java.awt.Dimension(725, 600));
        wrappingPanel.setMinimumSize(new java.awt.Dimension(725, 600));
        wrappingPanel.setPreferredSize(new java.awt.Dimension(725, 600));
        wrappingPanel.setBounds(0, 0, 725, 423);

        contentPanel.setBackground(new java.awt.Color(2, 148, 75));
        contentPanel.setMaximumSize(new java.awt.Dimension(305, 530));
        contentPanel.setMinimumSize(new java.awt.Dimension(305, 530));
        contentPanel.setPreferredSize(new java.awt.Dimension(305, 530));
        contentPanel.setLocation(35, 35);
        contentPanel.setSize(725 - 70, 76 + 18 + 55 + 18 + 55 + 18 + 55 + 18 + 40);
        contentPanel.setLayout(null);

        logoLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        logoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/appointment/autoWUŚ_check_logo.png"))); // NOI18N
        logoLabel.setText("");
        logoLabel.setMaximumSize(new java.awt.Dimension(139, 76));
        logoLabel.setMinimumSize(new java.awt.Dimension(139, 76));
        logoLabel.setPreferredSize(new java.awt.Dimension(139, 76));
        logoLabel.setBounds(0, 0, 139, 76);

        peselNoTexField.setText("Pesel");
        peselNoTexField.setMargin(new java.awt.Insets(2, 13, 2, 13));
        peselNoTexField.setMaximumSize(new java.awt.Dimension(305, 55));
        peselNoTexField.setMinimumSize(new java.awt.Dimension(305, 55));
        peselNoTexField.setPreferredSize(new java.awt.Dimension(305, 55));
        peselNoTexField.setBounds(0, 76 + 18, 305, 55);
        peselNoTexField.addMouseListener(new MouseAdapter(){
        	@Override
        	public void mouseClicked(MouseEvent e){
        		peselNoTexField.setText("");
        	}
        });
        
        idTextField.setText("Numer dowodu");
        idTextField.setMargin(new java.awt.Insets(2, 13, 2, 13));
        idTextField.setMaximumSize(new java.awt.Dimension(305, 55));
        idTextField.setMinimumSize(new java.awt.Dimension(305, 55));
        idTextField.setPreferredSize(new java.awt.Dimension(305, 55));
        idTextField.setBounds(0, 76 + 18 + 55 + 18, 305, 55);
        idTextField.addMouseListener(new MouseAdapter(){
        	@Override
        	public void mouseClicked(MouseEvent e){
        		idTextField.setText("");
        	}
        });
        
        calendarPanel.setBackground(new java.awt.Color(2, 148, 75));
        calendarPanel.setMaximumSize(new java.awt.Dimension(305, 229));
        calendarPanel.setMinimumSize(new java.awt.Dimension(305, 209));
        calendarPanel.setPreferredSize(new java.awt.Dimension(305, 170));
        //calendarPanel.setBounds(345, 76 + 18 - 3 - 55 - 18, 305, 209); /*76 + 18 - 3*/ // with Ubuntu
        calendarPanel.setBounds(345, 76 + 18 - 3 - 55 - 1, 305, 200); /*76 + 18 - 3*/ // with Tahoma
        calendarPanel.add(exDCL);

        Date date = new Date();
        timeSpinner.setModel(new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY));
        timeSpinner.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 13, 2, 13));
        timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, "hh:mm"));
        timeSpinner.setBounds(345, 76 + 18 + 55 + 18 + 55 + 18, 305, 55);
        
        addBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/appointment/autoWUŚ_appointment_add.png")));
        addBtn.setText("");
        addBtn.setMaximumSize(new java.awt.Dimension(305, 55));
        addBtn.setMinimumSize(new java.awt.Dimension(305, 55));
        addBtn.setPreferredSize(new java.awt.Dimension(305, 55));
        addBtn.setBounds(0, 76 + 18 + 55 + 18 + 55 + 18, 305, 55);
        addBtn.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/appointment/autoWUŚ_appointment_add_clicked.png")));
        
        copyrightLabel.setForeground(new java.awt.Color(255, 255, 255));
        copyrightLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        copyrightLabel.setText("<html><center>All rights reserved ® & Copyright © 2013<br>by Completely Unprepared</center></html>");
        copyrightLabel.setToolTipText("");
        copyrightLabel.setBounds(0, 76 + 18 + 55 + 18 + 55 + 18 + 55 + 18, 305, 40);
        
        contentPanel.add(logoLabel);
        contentPanel.add(peselNoTexField);
        contentPanel.add(idTextField);
        contentPanel.add(calendarPanel);
        contentPanel.add(timeSpinner);
        contentPanel.add(addBtn);
        contentPanel.add(copyrightLabel);
        
        wrappingPanel.add(contentPanel);
        
        this.getContentPane().add(wrappingPanel);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 725, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 423, Short.MAX_VALUE)
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AppointmentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AppointmentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AppointmentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AppointmentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AppointmentFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
